<?php
session_start();
if($_SESSION['user']=="") {
    ?>
    <script>
        alert('当前未登录！');
        window.location.href='../login.html';
    </script>
    <?php
}
//连接数据库
try {
    function success(){
        $result=[
            'error' => 0,
            'message' => '成功'
        ];
        return json_encode($result);
    }
    function error($mag){
        $data = [
            'error' => 1,
            'message' => $mag
        ];
        return json_encode($data);
    }
    
    //连接数据库
    $db = new PDO('mysql:dbname=liaotian;host=106.14.7.147','root','123456');

    $search = $db->prepare('select roomId from room where roomId=:roomId');
    $data=[
        ':roomId' => $_POST['roomId']
    ];
    if($search->execute($data) === false){
        print_r($search->errorInfo());
    }
    $reSearch=$search->fetch();
    if($_POST['roomId'] !=$reSearch['roomId']){
        die(error('房间号码不存在'));
    }
    if(empty($_POST['roomId'])){
        die(error('房间号码不能为空'));
    }
    echo success();
} catch (PDOException $e) {
    echo 'Connection failed';
}
